<?php

namespace app\user\controller;

use app\common\model\Ecpm;
use app\common\model\MiniApp;
use app\common\model\Product as ProductModel;
use app\common\model\ProductCps;
use think\Controller;
use think\facade\Request;
use think\facade\Cache;
use think\facade\Config;

class Index extends  Controller
{

    //小程序列表
    public function app_list()
    {
        $page=Request::param('page',1);
        $pageSize=Request::param('pageSize',20);
        $classify=Request::param('classify','测评');

        $list=MiniApp::where([
            'status'=>1,
            'classify'=>$classify
        ])->page(1,$pageSize)->select();

        for ($i=0;$i<count($list);$i++){
            if($list[$i]->code=='test'){
                $list[$i]->product=ProductModel::where(['status'=>1,'mini_app_code'=>'test'])->page($page,100)->field(['data'],true)->select();
            }
            if($list[$i]->code=='test_cps'){
                $list[$i]->product=ProductCps::where(['status'=>1,'mini_app_code'=>'test'])->page($page,100)->field(['data'],true)->select();
            }
            if($list[$i]->code=='kuaishou'){
                $list[$i]->product=ProductModel::where(['status'=>1,'mini_app_code'=>'kuaishou'])->page($page,100)->field(['data'],true)->select();
            }
           try{
               $list[$i]->yesterday_ecpm= round(Ecpm::newestEcpm()/1000,3) ;
           }catch (\Exception $e){
               $list[$i]->yesterday_ecpm= round(Ecpm::newestEcpm()/1000,3) ;
           }
        }

        $this->result($list,200);
    }

    public function getaccesstoken(){

        $app_id = Config::get('miniprogram.wx.appid');
        $secret = Config::get('miniprogram.wx.secret');
        $token = Cache::get('token');
        if(!$token){
            $arr = httpGet('https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='.$app_id.'&secret='.$secret);
            $arr =json_decode($arr);
            Cache::set('token',$arr->access_token,7000);
            $token = Cache::get('token');
        }
        return  $token;
    }

    //文字检测
    public function contentCheck()
    {
        $access_token=$this->getaccesstoken();
        $d = $this->request->param();
        $url = 'https://api.weixin.qq.com/wxa/msg_sec_check?access_token='.$access_token;
        $data =["content"=> $d['content'],"version"=>2,"scene"=>1,"openid"=>$d['openid']];
        $callarr = send_post($url,$data);
        $callarr = json_decode($callarr);
      
        $this->result($callarr,200,'成功');
    }
    //简单介绍
    public function simple_desc()
    {
        $data2=[
            [
                'title'=>"暂无内容，请在系统后台设置",
                'desc'=>''
            ]
        ];

        $data=\app\common\model\Setting::getSettings('common_problem');

        //没有设置的时候给默认值
        if($data){
            $data=json_decode($data);
        }else{
            $data=$data2;
        }
        $this->result($data,200,'成功');
    }

    //新手教程
    public function tutorial()
    {
        $data=[
            //视频教程
           "video"=>[
                "https://lanchong.oss-cn-beijing.aliyuncs.com/douzuanshe/app/jiaocheng/video/3.mp4?time=".time()
           ],
            //图文教程
            "pic"=>[
                "https://lanchong.oss-cn-beijing.aliyuncs.com/douzuanshe/app/jiaocheng/pic/1.png",
                "https://lanchong.oss-cn-beijing.aliyuncs.com/douzuanshe/app/jiaocheng/pic/2.png",
                "https://lanchong.oss-cn-beijing.aliyuncs.com/douzuanshe/app/jiaocheng/pic/3.png",
                "https://lanchong.oss-cn-beijing.aliyuncs.com/douzuanshe/app/jiaocheng/pic/4.png",
                "https://lanchong.oss-cn-beijing.aliyuncs.com/douzuanshe/app/jiaocheng/pic/5.png",
                "https://lanchong.oss-cn-beijing.aliyuncs.com/douzuanshe/app/jiaocheng/pic/6.png",
                "https://lanchong.oss-cn-beijing.aliyuncs.com/douzuanshe/app/jiaocheng/pic/7.png",
                "https://lanchong.oss-cn-beijing.aliyuncs.com/douzuanshe/app/jiaocheng/pic/8.png",
                "https://lanchong.oss-cn-beijing.aliyuncs.com/douzuanshe/app/jiaocheng/pic/9.png",
                "https://lanchong.oss-cn-beijing.aliyuncs.com/douzuanshe/app/jiaocheng/pic/10.png",
                "https://lanchong.oss-cn-beijing.aliyuncs.com/douzuanshe/app/jiaocheng/pic/11.png",
                "https://lanchong.oss-cn-beijing.aliyuncs.com/douzuanshe/app/jiaocheng/pic/12.png",
                "https://lanchong.oss-cn-beijing.aliyuncs.com/douzuanshe/app/jiaocheng/pic/13.png",
                "https://lanchong.oss-cn-beijing.aliyuncs.com/douzuanshe/app/jiaocheng/pic/14.png",
                "https://lanchong.oss-cn-beijing.aliyuncs.com/douzuanshe/app/jiaocheng/pic/15.png",
                "https://lanchong.oss-cn-beijing.aliyuncs.com/douzuanshe/app/jiaocheng/pic/16.png",
                "https://lanchong.oss-cn-beijing.aliyuncs.com/douzuanshe/app/jiaocheng/pic/17.png",
            ]
        ];

        $data2=\app\common\model\Setting::getSettings('tutorial');

        if($data2){
            $data2=json_decode($data2);
        }else{
            $data2=$data;
        }
        $this->result($data2,200,'成功');
    }

    //专属定制
    public function for_u()
    {
        $data=[
            [
                'title'=>"什么是专属订制？",
                'desc'=>'专属订制是平台为用户提供多种抖音测试类小程序的运营方案,用户可以选择其中一种方案,自己做推广赚取收益,这种方式产生的收益全部进入用户的银行账户'
            ],
            [
                'title'=>"专属订制适合哪些用户群体？",
                'desc'=>'1.做自媒体的个人/团队;
2.拥有一定粉丝量的流量主;
3.想要做类似于"快变现"平台的创业者;'
            ],
            [
                'title'=>"专属定制包含哪些套餐？",
                'desc'=>' 【普通版】
价格：1000元
包含：抖音小程序（自选20题）
【商业版】
价格：6800元+2%抽成
包含：微信/APP端【会员/分销功能】+抖音端、技术支持、商业授权
【商业版Pro】
价格：18800万元
包含：微信/APP端（会员/分销功能）+抖音端、程序源码、技术支持、商业授权
'
            ],
        ];
        $this->result($data,200,'成功');
    }


    //抖音知识
    public function dy_knowledge()
    {
        $data=[
            [
                'title'=>"1.什么是Ecpm？",
                'desc'=>'Ecpm是每1000次广告完播量的价格，200Ecpm，就是说1000次广告完播后，产生200元价值，那么单次的广告完播价格为：200/1000=0.2元/次'
            ],
            [
                'title'=>"为什么每天的Ecpm都不一样？",
                'desc'=>'不同的广告价格不一样，每个抖音用户观看到的广告也是不一样的，因此价格上会有波动。'
            ],
            [
                'title'=>"什么是广告完播次数？",
                'desc'=>'抖音用户在抖音小程序中观看完整广告的次数。'
            ],
            [
                'title'=>"自己可不可以在抖音上一直看广告产生收益？",
                'desc'=>'不可以。每个抖音账号每天只有前两次的观看是有价值的。'
            ],
            [
                'title'=>"什么是预估Ecpm和预估收益？",
                'desc'=>'预估Ecpm值：平台把抖音公布的前一日的Ecpm值作为今天参考。预估收益：预估Ecpm值乘以今日完播量。'
            ],
            [
                'title'=>"苹果手机可以在抖音上使用吗？",
                'desc'=>'暂时不可以'
            ],
            [
                'title'=>"怎么知道自己在抖音上挂载的小程序是我的ID？",
                'desc'=>'用户通过扫描“快变现”平台里面的小程序二维码，进入到抖音小程序，第一次会提示绑定成功，后面每一次登陆不再提示，系统默认绑定成功。如果用户第一次是通过抖音APP搜索小程序（趣味测评屋）挂载的，不会提示，并且也没有挂在成功。'
            ],
        ];

            $this->result($data,200,'');
    }


    public function index()
    {
        $data= [
            'banner'=>[
                [
                    'url'=>'http://www.baidu.com',
                    'img'=>'https://lanchong.oss-cn-beijing.aliyuncs.com/douzuanshe/app/bd73b3f5558de7f0a0640156f09ef88.png',
                    'title'=>'快来加入快变现'
                ],
                [
                    'url'=>'http://www.baidu.com',
                    'img'=>'https://lanchong.oss-cn-beijing.aliyuncs.com/douzuanshe/app/ee6805d25a792aa6bc1b789afb6f6c7.jpg',
                    'title'=>'快变现会员机制'
                ],
            ],
            'notice'=>[
                '活动期间，会员免费大放送，领取方法：【个人中心】->【开通会员】'
            ],
        ];

        $this->result($data,200,'首页所有的数据');
    }

}
